package com.aspose.cells.a.d;

import com.aspose.cells.Color;
import com.aspose.cells.Encoding;
import com.aspose.cells.ImageOrPrintOptions;
import com.aspose.cells.zcfx;
import java.util.HashMap;
import java.util.Iterator;

public class zfp extends ze {
   private long f = 0L;
   private zbl g;
   private zcfx h;
   private boolean i = true;
   private ImageOrPrintOptions j;
   private HashMap k = new HashMap();

   public zfp() {
      this.j = new ImageOrPrintOptions();
   }

   public zfp(ImageOrPrintOptions var1) {
      this.j = var1;
   }

   public void a(zl var1, com.aspose.cells.b.a.d.zm var2, String var3) throws Exception {
      this.g = new zbl(var3);
      this.h = new zcfx(var2, Encoding.getUTF8());
      var1.a((ze)this);
      this.h.e();
   }

   public void a(zm var1) throws Exception {
      this.h.a((int)1);
      this.h.b(true);
      this.h.b("svg");
      this.h.a("xmlns", "http://www.w3.org/2000/svg");
      this.h.a("xmlns:xlink", "http://www.w3.org/1999/xlink");
      if (this.j.getSVGFitToViewPort()) {
         this.h.a("width", "100%");
         this.h.a("height", "100%");
         this.h.a("viewBox", "0 0 " + var1.b() * 96.0F / 72.0F + " " + var1.c() * 96.0F / 72.0F);
      } else {
         this.h.a("width", "" + var1.b() + "pt");
         this.h.a("height", "" + var1.c() + "pt");
      }

      this.h.b("g");
      this.h.a("id", "SFixTitle");
      this.h.b();
      this.h.b("g");
      this.h.a("id", "SContent");
      this.h.b("g");
      this.h.a("transform", "scale(1.33333)");
   }

   public void b(zm var1) throws Exception {
      this.h.b();
      this.h.b();
      this.c();
      this.h.b();
      this.h.d();
   }

   private void c() throws Exception {
      this.h.b("defs");
      Iterator var1 = this.k.keySet().iterator();

      while(var1.hasNext()) {
         long var2 = (Long)var1.next();
         Object var4 = this.k.get(var2);
         if (var4 instanceof zfo) {
            this.h.b("pattern");
            this.a("id", "PATTERN" + var2);
            this.a("patternUnits", "userSpaceOnUse");
            zfo var5 = (zfo)var4;
            zj var6 = var5.b;
            float var7 = (float)var6.f().b();
            float var8 = (float)var6.f().c();
            if (var5.a != null) {
               var7 *= var5.a.e()[0];
               var8 *= var5.a.e()[3];
            }

            this.a("width", var7);
            this.a("height", var8);
            var6.a(new com.aspose.cells.b.a.b.zt(var7, var8));
            this.b(var6);
            this.h.b();
         } else {
            zg var9 = (zg)var4;
            this.h.b("linearGradient");
            this.a("id", "PATTERN" + var2);
            this.a("x1", var9.d().d());
            this.a("x2", var9.c().d());
            this.a("y1", var9.d().e());
            this.a("y2", var9.c().e());
            this.a("gradientUnits", "userSpaceOnUse");
            this.h.b("stop");
            this.a("offset", "0");
            this.a("style", "stop-color:" + a(var9.b()) + ";");
            this.h.b();
            this.h.b("stop");
            this.a("offset", "1");
            this.a("style", "stop-color:" + a(var9.a()) + ";");
            this.h.b();
            this.h.b();
         }
      }

      this.h.b();
   }

   private String c(zn var1) throws Exception {
      this.h.b("defs");
      this.h.b("clipPath");
      String var2 = "CLIP" + this.d();
      this.a("id", var2);
      this.h.b("path");
      zgl var3 = new zgl(true);
      String var4 = var3.a(var1, true);
      this.a("d", var4);
      this.h.b();
      this.h.b();
      this.h.b();
      return var2;
   }

   public void a(zb var1) throws Exception {
      boolean var2 = zaz.d(var1);
      String var3 = "";
      if (var2) {
         var3 = this.c(var1.b());
      }

      this.h.b("g");
      if (var1.a() != null || var2) {
         if (var1.a() != null) {
            float[] var4 = var1.a().e();
            this.a("transform", com.aspose.cells.b.a.zv.a("matrix({0},{1},{2},{3},{4},{5})", a(var4[0]), a(var4[1]), a(var4[2]), a(var4[3]), a(var4[4]), a(var4[5])));
         }

         if (var2) {
            this.a("clip-path", "url(#" + var3 + ")");
         }
      }

      if (var1 instanceof zc) {
         zc var8 = (zc)var1;
         this.a("id", "C_" + var8.a + "_" + var8.b + "_" + var8.c + "_" + var8.d + "_" + var8.e);
         zn var5 = zn.b(var8.f);
         this.h.b("path");
         zgl var6 = new zgl();
         String var7 = var6.a(var5, true);
         this.a("d", var7);
         this.a("stroke", "none");
         this.a("fill", "white");
         this.a("fill-opacity", "1");
         this.h.b();
         var5 = null;
      }

   }

   public void b(zb var1) throws Exception {
      this.h.b();
   }

   public void a(zf var1) throws Exception {
      this.h.b("text");
      this.a("x", var1.g().d());
      this.a("y", var1.g().e());
      zav var2 = var1.d();
      this.a("font-family", var2.a());
      this.a("font-size", var2.b());
      this.a("fill", var1.e());
      if (var2.d()) {
         this.a("font-weight", "bold");
      }

      if (var2.e()) {
         this.a("font-style", "italic");
      }

      if (var1.a() != null) {
         float[] var3 = var1.a().e();
         this.a("transform", com.aspose.cells.b.a.zv.a("matrix({0},{1},{2},{3},{4},{5})", a(var3[0]), a(var3[1]), a(var3[2]), a(var3[3]), a(var3[4]), a(var3[5])));
      }

      this.h.a(var1.h());
      this.h.b();
   }

   private String b(zj var1) throws Exception {
      String var2 = "Image" + this.d();
      switch(var1.e()) {
      case 1:
      case 2:
         zb var8 = zch.a(var1);
         var8.a(var1.g());
         var8.a((ze)this);
      case 3:
      default:
         break;
      case 4:
      case 5:
      case 6:
      case 7:
         this.h.b("image");
         this.a("Id", var2);
         this.a("x", var1.b().d());
         this.a("y", var1.b().e());
         this.a("width", var1.c().b());
         this.a("height", var1.c().c());
         String var3;
         if (!this.i) {
            var3 = this.g.a(var1.e());
            com.aspose.cells.b.a.d.ze var4 = com.aspose.cells.b.a.d.zd.a(var3);

            try {
               var4.b(var1.d(), 0, var1.d().length);
            } finally {
               if (var4 != null) {
                  var4.a();
               }

            }

            this.a("xlink:href", this.g.a(var3));
         } else {
            var3 = "";
            switch(var1.e()) {
            case 4:
               var3 = "data:image/jpeg;base64,";
               break;
            case 5:
               var3 = "data:image/png;base64,";
               break;
            case 6:
               var3 = "data:image/bmp;base64,";
               break;
            case 7:
               var3 = "data:image/gif;base64,";
            }

            this.a("xlink:href", var3 + com.aspose.cells.b.a.ze.a(var1.d()));
         }

         this.h.b();
      }

      return var2;
   }

   public void a(zj var1) throws Exception {
      this.b(var1);
   }

   public void a(zn var1) throws Exception {
      this.h.b("path");
      zgl var2 = new zgl();
      String var3 = var2.a(var1, false);
      this.a("d", var3);
      if (var1.a != null) {
         this.a("stroke", var1.a.a);
         this.a("stroke-opacity", (float)(var1.a.a.getA() & 255) / 255.0F);
         this.a("stroke-width", var1.a.b);
         if (var1.a.g == 0) {
            this.a("stroke-linecap", zfn.b(var1.a.c).toLowerCase());
            this.a("stroke-linejoin", zgf.a(var1.a.f).toLowerCase());
         } else {
            this.a("stroke-linecap", zfn.a(var1.a.e).toLowerCase());
            this.a("stroke-dasharray", zgf.a(zgf.a(var1.a)));
         }
      } else {
         this.a("stroke", "none");
         this.a("stroke-width", 0.0F);
      }

      if (var1.d() != null) {
         if (var1.d() instanceof com.aspose.cells.b.a.b.zu) {
            com.aspose.cells.b.a.b.zu var4 = (com.aspose.cells.b.a.b.zu)var1.d();
            this.a("fill", var4.a());
            this.a("fill-opacity", (float)(var4.a().getA() & 255) / 255.0F);
         } else if (var1.d() instanceof com.aspose.cells.b.a.b.zx) {
            com.aspose.cells.b.a.b.zx var7 = (com.aspose.cells.b.a.b.zx)com.aspose.cells.b.a.zl.a(var1.d(), com.aspose.cells.b.a.b.zx.class);
            this.a(var7);
         } else if (var1.d() instanceof com.aspose.cells.b.a.b.a.zg) {
            this.a((com.aspose.cells.b.a.b.zc)((com.aspose.cells.b.a.b.a.zg)var1.d()));
         } else if (var1.d() instanceof zg) {
            zg var8 = (zg)var1.d();
            long var5 = this.d();
            this.k.put(var5, var8);
            this.a("fill", "url(#PATTERN" + var5 + ")");
         }
      } else {
         this.a("fill", "none");
      }

      if (var1.a() != null) {
         this.a("transform", "matrix(" + zgf.a(var1.a()) + ")");
      }

   }

   public void a(zk var1) throws Exception {
      if (var1 != null && var1.c != null) {
         this.h.b("path");
         String var2 = "M " + zgf.a(var1.a) + " L " + zgf.a(var1.b);
         this.a("d", var2);
         this.a("stroke", var1.c.a);
         this.a("stroke-width", var1.c.b);
         if (var1.c.g != 0) {
            this.a("stroke-linecap", zfn.a(var1.c.e).toLowerCase());
            this.a("stroke-dasharray", zgf.a(zgf.a(var1.c)));
         }

         this.a("fill", "none");
         this.h.b();
      }

   }

   private void a(com.aspose.cells.b.a.b.zc var1) throws Exception {
      byte[] var2 = zbb.a((com.aspose.cells.b.a.b.a.zg)var1);
      zbm var3 = zbn.b(var2);
      com.aspose.cells.b.a.b.zq var4 = new com.aspose.cells.b.a.b.zq(0.0F, 0.0F, (float)var3.b(), (float)var3.c());
      this.a(var2, var4, 0, (com.aspose.cells.b.a.b.a.zi)null);
   }

   private void a(com.aspose.cells.b.a.b.zx var1) throws Exception {
      com.aspose.cells.a.c.zd var2 = new com.aspose.cells.a.c.zd(var1);

      try {
         byte[] var3 = zgk.a(var2);

         try {
            zbm var4 = zbn.b(var3);
            com.aspose.cells.b.a.b.zq var5 = new com.aspose.cells.b.a.b.zq(0.0F, 0.0F, (float)var4.b(), (float)var4.c());
            this.a(var3, var5, var1.c(), var1.b().b());
         } catch (Exception var9) {
            ;
         }
      } finally {
         if (var2 != null) {
            var2.a();
         }

      }

   }

   public String a(byte[] var1, com.aspose.cells.b.a.b.zq var2, int var3, com.aspose.cells.b.a.b.a.zi var4) throws Exception {
      zj var5 = new zj(var2.d(), var2.e(), var1);
      zfo var6 = new zfo();
      var6.b = var5;
      var6.a = var4;
      long var7 = this.d();
      this.k.put(var7, var6);
      this.a("fill", "url(#PATTERN" + var7 + ")");
      return "";
   }

   public void b(zn var1) throws Exception {
      this.h.b();
   }

   private void a(String var1, float var2) throws Exception {
      this.h.a(var1, a(var2));
   }

   private void a(String var1, Color var2) throws Exception {
      if (var2 != null) {
         this.h.a(var1, a(var2));
      }

   }

   private void a(String var1, String var2) throws Exception {
      this.h.a(var1, var2);
   }

   private static String a(float var0) {
      return com.aspose.cells.a.c.zp.a(var0);
   }

   private static String a(Color var0) {
      return com.aspose.cells.b.a.zv.a("#{0}{1}{2}", com.aspose.cells.a.c.zp.c(var0.getR() & 255), com.aspose.cells.a.c.zp.c(var0.getG() & 255), com.aspose.cells.a.c.zp.c(var0.getB() & 255));
   }

   private long d() {
      return (long)(this.f++);
   }
}
